//
//  XTXFJViewController.m
//  xiaotianxin
//
//  Created by txx on 2019/11/18.
//  Copyright © 2019 XYC. All rights reserved.
//

#import "XTXFJViewController.h"
#import "XTXFJCell.h"
#import <CTAssetsPickerController.h>
#import <YBImageBrowser.h>

@interface XTXFJViewController ()<UICollectionViewDataSource,UICollectionViewDelegate,CTAssetsPickerControllerDelegate>


@end
static NSString * const ID =@"XTXFJViewController";
@implementation XTXFJViewController


- (void)viewDidLoad {
    [super viewDidLoad];
    [self jiemianchushihua];
}

-(void)jiemianchushihua{
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc]init];
    CGFloat wh=(pingmuKuan - 8)/3;
    layout.itemSize=CGSizeMake(wh, wh);
    layout.minimumLineSpacing=2;
    layout.minimumInteritemSpacing=2;
    UICollectionView *collectionView=[[UICollectionView alloc]initWithFrame:self.view.bounds collectionViewLayout:layout];
    [self.view addSubview:collectionView];
    collectionView.showsVerticalScrollIndicator=NO;
    collectionView.showsHorizontalScrollIndicator=NO;
    collectionView.dataSource=self;
    [collectionView registerNib:[UINib nibWithNibName:NSStringFromClass(XTXFJCell.class) bundle:nil] forCellWithReuseIdentifier:ID];
    self.navigationController.navigationItem.leftBarButtonItem=[[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"后退按钮"] style:UIBarButtonItemStylePlain target:self action:@selector(gobackEventClick)];
    self.navigationController.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"选择" style:UIBarButtonItemStylePlain target:self action:@selector(chooseBtnClick)];
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
  
    
    
}
// 收到通知回调
- (void)didReceiveMessage:(NSNotification *)notification
{
  
    
}
-(void)gobackEventClick{
    [self.navigationController popViewControllerAnimated:YES];
}
-(void)chooseBtnClick{
    [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status){
        dispatch_async(dispatch_get_main_queue(), ^{
            // init picker
            CTAssetsPickerController *picker = [[CTAssetsPickerController alloc] init];
            // set delegate
            picker.delegate = self;
            // Optionally present picker as a form sheet on iPad
            if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
                picker.modalPresentationStyle = UIModalPresentationFormSheet;
            // present picker
            [self presentViewController:picker animated:YES completion:nil];
        });
    }];
}
#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 70;
}

- (__kindof UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    XTXFJCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    cell.FJImageView.image=[UIImage imageNamed:[@"iconImage" stringByAppendingFormat:@"%d",indexPath.item+1]];
    return cell;
}
- (void)getMobId
{
    // 构造自定义参数（可选）
    NSMutableDictionary *customParams = [NSMutableDictionary dictionary];
    customParams[@"key1"] = @"value1";
    customParams[@"key2"] = @"value2";
}
#pragma mark - CTAssetsPickerControllerDelegate
- (void)assetsPickerController:(CTAssetsPickerController *)picker didFinishPickingAssets:(NSArray *)assets
{
// assets contains PHAsset objects.
}
#pragma mark - UICollectionViewDelegate
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    YBIBImageData *data=[[YBIBImageData alloc]init];
//    data.imageName=[@"iconImage" stringByAppendingFormat:@"%d",indexPath.item+1];
    data.projectiveView=self.view;
    YBImageBrowser *browser = [YBImageBrowser new];
    browser.dataSourceArray = @[data];
    browser.currentPage = 0;
    [browser show];
}
@end
